/**
 * Created by Administrator on 15-6-17.
 */
var List = RichBase.extend({
	statics : { api : "call/jh_show.php"},
	EVENTS : {
		"click" : {
			".removeVenueBtn" : "removeVenue"
		}
	},
	init : function(opt){
		this.container = opt.container;
		this.getList();
	},
	removeVenue : function(that,e){
		e.preventDefault();
		var tarBtn = $(e.currentTarget);
		var venueid = tarBtn.attr("data-venueid");
		if(tarBtn.hasClass("loading") || !venueid) return false;
		var result = window.confirm("确定删除该场管？");
		if(!result) return false;
		PFT.Ajax({
			url : that.statics.api,
			type : "GET",
			dataType : "json",
			data : {
				action : "remove_venue",
				venue_id : venueid
			},
			loading : function(){ tarBtn.text("删除中...")},
			removeLoading : function(){ tarBtn.text("删除")},
			timeout : function(){ alert("网络请求超时，请稍重试")},
			serverError : function(){ alert("网络请求失败，请稍重试")}
		},function(res){
			if(res.status=="success"){
				tarBtn.parents(".venueItem").remove();
				PFT_GLOBAL.U.Alert("success",'<p style="width:120px">删除成功</p>');
			}else{
				var msg = res.msg || "删除失败";
				PFT_GLOBAL.U.Alert("fail",'<p style="width:160px">'+msg+'</p>');
			}
		})

	},
	getList : function(){
		var that = this;
		var ohtml = this.container.html();

		PFT.Ajax({
			url : that.statics.api,
			type : "GET",
			dataType : "json",
			data : {
				action : "get_venue_list"
			},
			loading : function(){
				that.container.html('<li style="width:100%; height:200px; line-height:200px; clear:both; text-align:center; font-size:14px;">正在加载数据...</li>')
			},
			removeLoading : function(){
				that.container.html(ohtml);
			},
			timeout : function(){ alert("网络请求超时，请稍重试")},
			errorServer : function(){ alert("网络请求失败，请稍重试")}
		},function(res){
			if(res.status=="success"){
				var list = res.data;
				var html = "";
				for(var i in list){
					var data = list[i];
					data["venue_thumb"] = data["venue_thumb"] || "http://www.12301.cc/tpl/membercard/images/defaultThum.gif";
					html += that.parseTemplate($("#venueListTpl").html(),data);
				}
				that.container.prepend(html);
			}
		})
	}
});

new List({container:$("#venueUl")})




















